<template>
  <a-card title="补考规则设置">
    <a-form :form="form" @submit="handleSubmit">
      <a-form-item label="允许补考成绩范围">
        <a-input-number 
          v-decorator="['minScore', { initialValue: 60 }]" 
          :min="0" 
          :max="100" 
          placeholder="最低分"
        />
        ~
        <a-input-number 
          v-decorator="['maxScore', { initialValue: 80 }]" 
          :min="0" 
          :max="100" 
          placeholder="最高分"
        />
      </a-form-item>
      
      <a-form-item label="允许补考年级">
        <a-checkbox-group v-decorator="['grades', { initialValue: ['大一', '大二'] }]">
          <a-checkbox v-for="grade in gradeOptions" :key="grade" :value="grade">
            {{ grade }}
          </a-checkbox>
        </a-checkbox-group>
      </a-form-item>
      
      <a-form-item label="允许补考特殊情况">
        <a-checkbox-group v-decorator="['specialCases', { initialValue: ['medical'] }]">
          <a-checkbox v-for="case1 in specialCaseOptions" :key="case1.value" :value="case1.value">
            {{ case1.label }}
          </a-checkbox>
        </a-checkbox-group>
      </a-form-item>
      
      <a-form-item label="允许补考的学年学期">
        <a-select
          v-decorator="['academicYear', { initialValue: '2022-2023' }]"
          placeholder="请选择学年"
        >
          <a-select-option v-for="year in academicYearOptions" :key="year">
            {{ year }}
          </a-select-option>
        </a-select>
        
        <a-select
          v-decorator="['semester', { initialValue: '1' }]"
          placeholder="请选择学期"
          style="margin-left: 10px;"
        >
          <a-select-option value="1">第一学期</a-select-option>
          <a-select-option value="2">第二学期</a-select-option>
        </a-select>
      </a-form-item>
      
      <a-form-item>
        <a-button type="primary" html-type="submit">保存规则</a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
export default {
  beforeCreate() {
    this.form = this.$form.createForm(this)
  },
  
  data() {
    return {
      gradeOptions: ['大一', '大二', '大三', '大四'],
      specialCaseOptions: [
        { value: 'medical', label: '因病缺考' },
        { value: 'family', label: '家庭突发情况' },
        { value: 'competition', label: '代表学校参赛' }
      ],
      academicYearOptions: ['2020-2021', '2021-2022', '2022-2023']
    }
  },
  
  methods: {
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$message.success('规则保存成功')
          console.log('保存的规则:', values)
        }
      })
    }
  }
}
</script>